<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]="formGroup" class="formGroup">
  <div class="aui-header-2 aui-gutter-column-sm">
    <h2>{{ 'common_basic_info_label' | i18n }}</h2>
  </div>
  <lv-form-item>
    <lv-form-label lvRequired>
      {{ 'common_name_label' | i18n }}
    </lv-form-label>
    <lv-form-control [lvErrorTip]="nameErrorTip">
      <input lv-input type="text" formControlName="policyName" />
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label>
      {{ 'common_desc_label' | i18n }}
    </lv-form-label>
    <lv-form-control>
      <lv-input-lint>
        <textarea
          formControlName="description"
          maxlength="255"
          rows="4"
          lv-input
          style="resize: vertical;"
        ></textarea>
      </lv-input-lint>
    </lv-form-control>
  </lv-form-item>
  <div class="aui-header-2 aui-gutter-column-sm mgt-10">
    <h2>
      {{
        (isX3000 ? 'common_worm_policy_label' : 'common_anti_policy_label')
          | i18n
      }}
    </h2>
  </div>

  <lv-form-item *ngIf="!isX3000">
    <lv-form-label>
      {{ 'operation_target_antiransomwarepolicy_label' | i18n }}
      <i
        lv-icon="aui-icon-help"
        lv-tooltip="{{ antiRansomwareTip}}"
        lvTooltipTheme="light"
        class="configform-constraint"
        lvColorState="true"
      ></i>
    </lv-form-label>
    <lv-form-control>
      <lv-group lvDirection="vertical">
        <lv-switch formControlName="needDetect" [lvDisabled]="isDisableRansomware"></lv-switch>
      </lv-group>
    </lv-form-control>
  </lv-form-item>
  <ng-container *ngIf="formGroup.value.needDetect">
    <lv-form-item>
      <lv-form-label lvRequired>{{
        'common_scheduled_label' | i18n
      }}</lv-form-label>
      <lv-form-control>
        <lv-radio-group
          formControlName="schedulePolicy"
          [lvGroupName]="'timeGroup'"
        >
          <lv-group
            [lvGutter]="'16px'"
            lvDirection="vertical"
            class="archival-element-width"
          >
            <lv-radio [lvValue]="dataMap.Scheduling_Plan.immediately.value">
              {{ dataMap.Scheduling_Plan.immediately.label | i18n }}
            </lv-radio>
            <lv-radio [lvValue]="dataMap.Scheduling_Plan.interval.value">
              {{ dataMap.Scheduling_Plan.interval.label | i18n }}
            </lv-radio>
          </lv-group>
        </lv-radio-group>
      </lv-form-control>
    </lv-form-item>
    <ng-container
      *ngIf="
        formGroup.value.schedulePolicy ===
        dataMap.Scheduling_Plan.interval.value
      "
    >
      <lv-form-item>
        <lv-form-label lvRequired
          >{{ 'explore_detected_frequency_label' | i18n }}
        </lv-form-label>
        <lv-form-control [lvErrorTip]="intervalErrorTip">
          <lv-group lvGutter="8px">
            <span>
              {{ 'common_every_label' | i18n }}
            </span>
            <lv-input-group
              [lvAddAfter]="unitTpl"
              class="input-group-select-right interval-input-group"
            >
              <input
                lv-input
                formControlName="interval"
                placeholder="{{
                  formGroup.value.intervalUnit === 'm'
                    ? '1~59'
                    : formGroup.value.intervalUnit === 'h'
                    ? '1~23'
                    : formGroup.value.intervalUnit === 'd'
                    ? '1~7'
                    : '1~4'
                }}"
              />
            </lv-input-group>
            <ng-template #unitTpl>
              <lv-select
                [lvOptions]="intervalUnit"
                formControlName="intervalUnit"
                class="unit-inner-select"
                lvValueKey="value"
                (ngModelChange)="changeTimeUnits($event)"
              ></lv-select>
            </ng-template>
            <lv-group>
              <span class="group-span sub-label" style="width: 100px;">
                {{ 'explore_detecte_label' | i18n }}
              </span>
            </lv-group>
          </lv-group>
        </lv-form-control>
      </lv-form-item>
      <lv-form-item>
        <lv-form-label lvRequired
          >{{ 'explore_detected_first_time_label' | i18n }}
        </lv-form-label>
        <lv-form-control [lvErrorTip]="firstTimeErrorTip">
          <lv-date-picker
            lvShowTime="true"
            formControlName="startDetectionTime"
            class="date-picker"
          >
          </lv-date-picker>
        </lv-form-control>
      </lv-form-item>
    </ng-container>
    <ng-container
      *ngIf="
        formGroup.value.schedulePolicy ===
        dataMap.Scheduling_Plan.interval.value
      "
    >
      <lv-form-item>
        <lv-form-label></lv-form-label>
        <lv-form-control>
          <lv-form-label
            >{{ 'explore_detect_range_label' | i18n }}
          </lv-form-label>
          <lv-form-control>
            <lv-radio-group
              formControlName="detectionType"
              [lvGroupName]="'rangeGroup'"
              class="range-group"
            >
              <lv-group
                [lvGutter]="'16px'"
                lvDirection="vertical"
                class="archival-element-width"
              >
                <lv-radio [lvValue]="dataMap.Detecting_Range.last.value">
                  {{ dataMap.Detecting_Range.last.label | i18n }}
                </lv-radio>
                <lv-radio [lvValue]="dataMap.Detecting_Range.all.value">
                  {{ dataMap.Detecting_Range.all.label | i18n }}
                </lv-radio>
                <lv-radio [lvValue]="dataMap.Detecting_Range.specified.value">
                  {{ dataMap.Detecting_Range.specified.label | i18n }}
                </lv-radio>
                <ng-container
                  *ngIf="
                    formGroup.value.detectionType ===
                    dataMap.Detecting_Range.specified.value
                  "
                >
                  <lv-form-control [lvErrorTip]="specifiedTimeErrorTip">
                    <lv-date-picker
                      lvShowTime="true"
                      class="date-picker"
                      formControlName="copyTime"
                    >
                    </lv-date-picker>
                  </lv-form-control>
                </ng-container>
              </lv-group>
            </lv-radio-group>
          </lv-form-control>
        </lv-form-control>
      </lv-form-item>
    </ng-container>
  </ng-container>

  <lv-form-item>
    <lv-form-label>
      {{ 'common_worm_policy_label' | i18n }}
    </lv-form-label>
    <lv-form-control>
      <lv-switch formControlName="setWorm"></lv-switch>
    </lv-form-control>
  </lv-form-item>
  <ng-container *ngIf="formGroup.value.setWorm">
    <ng-container *ngIf="false">
      <lv-form-item>
        <lv-form-label lvRequired>{{
          'explore_anti_tampering_setting_label' | i18n
        }}</lv-form-label>
        <lv-form-control>
          <lv-select
            [lvOptions]="antiTamperingSettingOptions"
            formControlName="antiTamperingSetting"
            lvValueKey="value"
          >
          </lv-select>
        </lv-form-control>
      </lv-form-item>
    </ng-container>
    <lv-form-item>
      <lv-form-label>
        {{ 'explore_anti_tampering_setting_label' | i18n: []:true }}
      </lv-form-label>
      <lv-form-control>
        {{
          (formGroup.value.antiTamperingSetting === '0'
            ? 'explore_anti_setting_01_label'
            : 'explore_anti_setting_02_label'
          ) | i18n
        }}
      </lv-form-control>
    </lv-form-item>
  </ng-container>

  <lv-form-item>
    <div class="aui-header-2 aui-gutter-column-sm mgt-10">
      <h2 style="width: 200px;">
        {{ 'explore_resource_object_label' | i18n }}
      </h2>
    </div>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label>{{ 'common_type_label' | i18n }}</lv-form-label>
    <lv-form-control>
      <div class="archive-time-container">
        <lv-radio-group
          formControlName="dataSourceType"
          [lvGroupName]="'timeGroup'"
        >
          <lv-group [lvGutter]="'16px'" lvDirection="vertical">
            <lv-radio [lvValue]="dataMap.Detecting_Data_Source.local.value">
              {{ dataMap.Detecting_Data_Source.local.label | i18n }}
            </lv-radio>
            <lv-radio [lvValue]="dataMap.Detecting_Data_Source.external.value">
              {{ dataMap.Detecting_Data_Source.external.label | i18n }}
            </lv-radio>
          </lv-group>
        </lv-radio-group>
      </div>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label lvRequired
      >{{ 'common_resource_type_label' | i18n }}
    </lv-form-label>
    <lv-form-control>
      <lv-select
        [lvOptions]="resourceTypes"
        formControlName="resourceSubType"
        lvValueKey="value"
        lvShowFilter
        lvFilterKey="label"
        lvFilterMode="contains"
      >
      </lv-select>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label></lv-form-label>
    <lv-form-control>
      <lv-tabs
        [(lvActiveIndex)]="activeIndex"
        (lvActiveIndexChange)="selectIndexChange($event)"
        [lvSize]="'small'"
      >
        <lv-tab [lvTitle]="total" [lvId]="'total'">
          <ng-template lv-tab-lazy>
            <lv-pro-table
              #resourceTable
              [config]="tableConfig"
              [data]="tableData"
            ></lv-pro-table>
          </ng-template>
        </lv-tab>
        <lv-tab [lvTitle]="selected" [lvId]="'selected'">
          <ng-template lv-tab-lazy>
            <lv-pro-table
              #seletedTable
              [config]="selectedTableConfig"
              [data]="selectedTableData"
            ></lv-pro-table>
          </ng-template>
        </lv-tab>
      </lv-tabs>
      <ng-template #total>
        <div class="host-register-tabnav tabnav-font">
          <span>{{ 'common_total_label' | i18n }}</span>
          <span class="host-register-tabnav-num">{{ currentTotal }}</span>
        </div>
      </ng-template>
      <ng-template #selected>
        <div class="host-register-tabnav tabnav-font">
          <span>{{ 'common_selected_label' | i18n }}</span>
          <span class="host-register-tabnav-num">{{ currentSelect }}</span>
        </div>
      </ng-template>
    </lv-form-control>
  </lv-form-item>
</lv-form>
<ng-template #tipContentTpl>
  <div [innerHTML]="typeChangeLabel"></div>
</ng-template>
